﻿<local:PageBase x:Class="MicroBlogClient.Letters"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:MicroBlogClient"
        xmlns:controls="clr-namespace:Rabbit.Controls;assembly=Rabbit.Controls"
      mc:Ignorable="d" 
      d:DesignHeight="300" d:DesignWidth="300"
	Title="Letters">
    <Page.Resources>
        <DataTemplate x:Key="InBoxLettersTemplate">
            <DataTemplate.Resources>
                <Storyboard x:Key="YellowFade">
                    <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="grid" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" FillBehavior="Stop">
                        <SplineColorKeyFrame KeyTime="00:00:00" Value="#FFFEFF76" />
                        <SplineColorKeyFrame KeyTime="00:00:20" Value="#19FEFF76" />
                    </ColorAnimationUsingKeyFrames>
                </Storyboard>
            </DataTemplate.Resources>
            <DockPanel Margin="0,10,0,10" x:Name="grid" Background="Transparent">
                <Border VerticalAlignment="Top" Width="40" >
                    <Border BorderBrush="White" DockPanel.Dock="Left" CornerRadius="5" Height="40" Width="40" BorderThickness="1">
                        <Image Stretch="UniformToFill"  Source="{Binding Sender.ProfileImageUrl, Converter={StaticResource ImageConverter}, IsAsync=True,Mode=OneTime}" />
                    </Border>
                </Border>
                <StackPanel Margin="10,0,0,0">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock TextWrapping="Wrap" Canvas.Top="0" Width="Auto"><Hyperlink CommandParameter="{Binding Sender.ScreenName}"  Click="link_OnUserNameClicked"><Run Text="{Binding Sender.ScreenName}"/></Hyperlink></TextBlock>
                        <controls:ImageEx Visibility="{Binding Sender.Verified, Converter={StaticResource BooleanToVisibilityConverter}}" Source="{StaticResource CertificateUser}" Height="18" Width="20"/>
                        <TextBlock Foreground="Gray" Margin="5,0,0,0"
                                   Text="{Binding CreatedAt, Converter={StaticResource ResourceKey=DateTimeFormatConverter}, IsAsync=True}"/>
                    </StackPanel>
                    <DockPanel Margin="10,10,0,0">
                        <!--Status text-->
                        <controls:TextBlockEx  OnUserNameClicked="link_OnUserNameClicked"  Foreground="{DynamicResource StatusForegroundBrush}" LineHeight="20" Text="{Binding Text, IsAsync=True}" DockPanel.Dock="Top" TextWrapping="Wrap">
                            <controls:TextBlockEx.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Header="复制" x:Name="menuCopyStatus" CommandParameter="{Binding Text}" Click="menuCopyStatus_Click"/>
                                </ContextMenu>
                            </controls:TextBlockEx.ContextMenu>
                        </controls:TextBlockEx>
                    </DockPanel>
                    <TextBlock  Margin="10,0,0,0">
                            <Hyperlink Click="ReplyLetter_Click" >
                                <Run Text="回复"/></Hyperlink>
                        		<TextBlock Margin="3,0,0,0"/>
                                    <Hyperlink CommandParameter="{Binding Id}" Click="DeleteInBoxLetter" ><Run Text="删除"/></Hyperlink>
                        		<TextBlock Margin="3,0,0,0"/>
                                    <Hyperlink CommandParameter="{Binding Sender}" Click="OpenChatWindow" ><Run Text="聊天"/></Hyperlink>
                        		</TextBlock>
                </StackPanel>
            </DockPanel>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding IsNew}" Value="true">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard Storyboard="{StaticResource YellowFade}" x:Name="YellowFade_BeginStoryboard" />
                    </DataTrigger.EnterActions>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
        <DataTemplate x:Key="OutBoxLettersTemplate">
            <DockPanel Margin="0,10,0,10" x:Name="grid" Background="Transparent">
                <Border VerticalAlignment="Top" Width="40" >
                    <Border BorderBrush="White" DockPanel.Dock="Left" CornerRadius="5" Height="40" Width="40" BorderThickness="1">
                        <Image Stretch="UniformToFill"  Source="{Binding Recipient.ProfileImageUrl, Converter={StaticResource ImageConverter}, IsAsync=True}" />
                    </Border>
                </Border>
                <StackPanel Margin="10,0,0,0">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock TextWrapping="Wrap" Canvas.Top="0" Width="Auto"><Hyperlink CommandParameter="{Binding Recipient.ScreenName}"  Click="link_OnUserNameClicked"><Run Text="{Binding Recipient.ScreenName}"/></Hyperlink></TextBlock>
                        <controls:ImageEx Visibility="{Binding Recipient.Verified, Converter={StaticResource BooleanToVisibilityConverter}}" Source="{StaticResource CertificateUser}" Height="18" Width="20"/>
                        <TextBlock Foreground="Gray" Margin="5,0,0,0" 
                                   Text="{Binding CreatedAt, Converter={StaticResource ResourceKey=DateTimeFormatConverter}, IsAsync=True}"/>
                    </StackPanel>
                    <DockPanel Margin="10,10,0,0">
                        <!--Status text-->
                        <controls:TextBlockEx  OnUserNameClicked="link_OnUserNameClicked"  Foreground="{DynamicResource StatusForegroundBrush}" LineHeight="20" Text="{Binding Text, IsAsync=True}" DockPanel.Dock="Top" TextWrapping="Wrap">
                            <controls:TextBlockEx.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Header="复制" x:Name="menuCopyStatus" CommandParameter="{Binding Text}" Click="menuCopyStatus_Click"/>
                                </ContextMenu>
                            </controls:TextBlockEx.ContextMenu>
                        </controls:TextBlockEx>
                    </DockPanel>
                    <TextBlock  Margin="10,0,0,0">
                             <Hyperlink CommandParameter="{Binding Id}" Click="DeleteOutBoxLetter" >
                                 <Run Text="删除"/></Hyperlink> 
                        		<TextBlock Margin="3,0,0,0"/> 
                                    <Hyperlink CommandParameter="{Binding Recipient}" Click="OpenChatWindow" ><Run Text="聊天"/></Hyperlink>
                    </TextBlock>
                </StackPanel>
            </DockPanel>
        </DataTemplate>
    </Page.Resources> 
        <Border Style="{DynamicResource MainContentBackground}" Margin="0,0,0,0">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid Grid.Row="0" Margin="16,0,16,0" Visibility="Collapsed" x:Name="gridReplyLetter" >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="35"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="0"/>
                    </Grid.RowDefinitions>
                    <DockPanel Grid.Row="0" VerticalAlignment="Center" Height="24">
                        <TextBlock Text="发私信给:" VerticalAlignment="Center"/>
                        <TextBox x:Name="txtSendTo" IsReadOnly="True" Margin="20,0,0,0"/>
                    </DockPanel>
                    <TextBox x:Name="txtLetterContent" Height="40"  TextWrapping="Wrap" PreviewKeyDown="txtLetterContent_PreviewKeyDown" AcceptsReturn="True" Grid.Row="1"/>
                    <StackPanel Margin="0,0,0,-25" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" >
                        <Button  x:Name="btnSend"  Click="btnSend_Click"
                             Content="发送" Visibility="{Binding Text,ElementName=txtLetterContent,Converter={StaticResource StringToVisibilityConverter}}" />
                        <Button  x:Name="btnCancel"   Margin="10,0,0,0" Click="btnCancel_Click"
                             Content="取消"/> 
                    </StackPanel>
                </Grid>
                <TabControl x:Name="tabLettersContent" BorderThickness="0" Grid.Row="1" >
                    <TabItem Header="收件箱"  Style="{DynamicResource SubHeaderMenuItemStyle}"  x:Name="tabItemInBox">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <ListBox Canvas.Left="0" Grid.Row="0" x:Name="lstInBox" BorderThickness="0"
                                                                 ItemContainerStyle="{DynamicResource ListBoxItemStyle}"  Margin="0"
                                                                 ScrollViewer.HorizontalScrollBarVisibility="Disabled"  
                                                                 ScrollViewer.CanContentScroll="False"
                                                                 ItemTemplate="{StaticResource ResourceKey=InBoxLettersTemplate}" 
                                                                 Foreground="Black"/>
                        <local:UCPager x:Name="pager"  Grid.Row="1" OnFirstPageClick="pager_OnFirstPageClick"
                           OnPreviousePage="pager_OnPreviousePage"
                           OnNextPageClick="pager_OnNextPageClick"/>
                    </Grid>
                </TabItem>
                    <TabItem Header="发件箱"  Style="{DynamicResource SubHeaderMenuItemStyle}" x:Name="tabItemOutBox">
                        <DockPanel>
                            <ListBox  x:Name="lstOutBox" Canvas.Left="0" Grid.Row="0" 
                                                          BorderThickness="0"
                                                           SelectionMode="Extended"
                                                                 ItemContainerStyle="{DynamicResource ListBoxItemStyle}"  Margin="0"
                                                                 ScrollViewer.HorizontalScrollBarVisibility="Disabled"  
                                                                 ScrollViewer.CanContentScroll="False"
                                                                 ItemTemplate="{StaticResource ResourceKey=OutBoxLettersTemplate}" 
                                                                 Foreground="Black"/>
                        </DockPanel>
                    </TabItem>
                </TabControl>

           
        </Grid>
        </Border> 
</local:PageBase>
